package 牛客;

public class 比较版本号 {
    public static int compareVersion(String version1, String version2) {
        String[] s1=version1.split("\\.");
        String[] s2=version2.split("\\.");

        for (int i=0;i<s1.length||i<s2.length;++i){
            int x = 0,y=0;
            if(i<s1.length){
                x=Integer.parseInt(s1[i]);
            }
            if(i<s2.length){
                y=Integer.parseInt(s2[i]);
            }
            System.out.println("x = " + x);
            System.out.println("y = " + y);
            if(x>y) return 1;
            if(x<y) return -1;

        }
        return 0;
    }

    public static void main(String[] args) {
        String version1="0.1";
        String version2="1.1";
        System.out.println("compareVersion(version1,version2) = " + compareVersion(version1, version2));
    }

    /*

     String[] v1 = version1.split("\\.");
        String[] v2 = version2.split("\\.");
        for (int i = 0; i < v1.length || i < v2.length; ++i) {
            int x = 0, y = 0;
            if (i < v1.length) {
                x = Integer.parseInt(v1[i]);
            }
            if (i < v2.length) {
                y = Integer.parseInt(v2[i]);
            }
            if (x > y) {
                return 1;
            }
            if (x < y) {
                return -1;
            }
        }
        return 0;

作者：LeetCode-Solution
链接：https://leetcode-cn.com/problems/compare-version-numbers/solution/bi-jiao-ban-ben-hao-by-leetcode-solution-k6wi/
来源：力扣（LeetCode）
著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。
     */
}
